package cn.sinata.wanglin.adapter;

import android.view.View;

import com.facebook.drawee.view.SimpleDraweeView;
import com.hyphenate.easeui.utils.EaseSmileUtils;
import com.xilada.xldutils.adapter.HFRecyclerAdapter;
import com.xilada.xldutils.adapter.util.ViewHolder;
import com.xilada.xldutils.utils.ActivityUtil;
import com.xilada.xldutils.utils.TimeUtils;

import java.util.List;

import cn.sinata.wanglin.R;
import cn.sinata.wanglin.model.CircleMessage;
import cn.sinata.wanglin.neighbor.activity.MineCircleActivity;
import cn.sinata.wanglin.utils.ImageUtil;

/**
 *
 * Created by liaoxiang on 16/12/17.
 */

public class NewCircleMessageAdapter extends HFRecyclerAdapter<CircleMessage> {
    public NewCircleMessageAdapter(List<CircleMessage> mData) {
        super(mData, R.layout.item_new_circle_message_layout);
    }

    @Override
    public void onBind(int position, final CircleMessage circleMessage, ViewHolder holder) {
        SimpleDraweeView imageView = holder.bind(R.id.image);
        SimpleDraweeView headView = holder.bind(R.id.headView);
        if (circleMessage.getImgList().size() > 0) {
            imageView.setVisibility(View.VISIBLE);
            String url = circleMessage.getImgList().get(0).getImgUrl();
            imageView.setImageURI(ImageUtil.parseImageUri(url));
        } else {
            imageView.setVisibility(View.GONE);
        }
        headView.setImageURI(ImageUtil.parseImageUri(circleMessage.getHeadUrl()));
        holder.setText(R.id.tv_name,circleMessage.getUserName());
        holder.setText(R.id.tv_time, TimeUtils.getTimeInterval(circleMessage.getCreateDate(),circleMessage.getSystemDate()));
        holder.setText(R.id.tv_content, EaseSmileUtils.getSmiledText(mContext,circleMessage.getContent()));
        holder.setText(R.id.tv_circle_content,EaseSmileUtils.getSmiledText(mContext,circleMessage.getCircleContent()));
        headView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ActivityUtil.create(mContext)
                        .go(MineCircleActivity.class)
                        .put("id",String.valueOf(circleMessage.getUserID()))
                        .start();
            }
        });
    }
}
